//
//  AuctionLogisticsVC.m
//  MyNewProject
//
//  Created by 王春辉 on 2020/1/5.
//  Copyright © 2020年 sun. All rights reserved.
//

#import "AuctionLogisticsVC.h"
#import "AuctionLogisticsTableViewCell.h"

#pragma mark -- mark 数据相关
#import "AuctionLogisticsModel.h"

@interface AuctionLogisticsVC ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@end
static NSString *const identifier = @"cell_identifier";
@implementation AuctionLogisticsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.gk_navTitle = @"物流信息";
    self.view.backgroundColor = SKColorWithHex(0xF7F7F7);
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_offset(0);
        make.top.mas_offset(SKTopBar_Height);
        make.bottom.mas_offset(-SKBottomSafe_Height);
    }];
}

#pragma mark -- mark 懒加载

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.showsHorizontalScrollIndicator = false;
        _tableView.showsVerticalScrollIndicator = false;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.tableFooterView = [UIView new];
        _tableView.tableHeaderView = [UIView new];
        [_tableView registerClass:[AuctionLogisticsTableViewCell class] forCellReuseIdentifier:identifier];
        _tableView.backgroundColor = self.view.backgroundColor;
        [self.view addSubview:_tableView];
    }
    return _tableView;
}

#pragma mark -- mark UITableViewDelegate UITableViewDataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    AuctionLogisticsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
    AuctionLogisticsInfoModel *model = self.logisticsData[indexPath.section];
    cell.name = @"商品";
    cell.orderCode = model.wuliu_num;
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:SS";
    NSString *dateString = [dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:[model.time integerValue]]];
    cell.time = dateString;
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.logisticsData.count;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:true];
    // 查看详情
    AuctionLogisticsInfoModel *model = self.logisticsData[indexPath.section];
    [self showMessage:model.wuliu_num];
}
@end
